import time

from selenium.webdriver.common.by import By

from common.Utils import BlogDriver

class BlogListTest:
    url = ""
    driver = ""
    def __init__(self):
        self.url = "http://127.0.0.1:9580/index.html"
        self.driver = BlogDriver.driver
        self.driver.get(self.url)

    #元素检测
    def ListEleTest(self):
        #博客分类标签是否可以点击切换
        self.driver.find_element(By.CSS_SELECTOR,"#topBoardList > li:nth-child(2) > a > span.nav-link-title").click()
        self.driver.find_element(By.CSS_SELECTOR,"#article_list_board_title")
        BlogDriver.getScreeShot()
        self.driver.find_element(By.CSS_SELECTOR, "#topBoardList > li.nav-item.active > a > span.nav-link-title").click()
        self.driver.find_element(By.CSS_SELECTOR, "#article_list_board_title")
        BlogDriver.getScreeShot()


        #”+发布帖子“是否可以点击跳转
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div.col-auto.ms-auto.d-print-none > div > a.btn.btn-primary.d-none.d-sm-inline-block.article_post").click()
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div > h2")
        BlogDriver.getScreeShot()
        self.driver.back()

        #博客名是否可以点击跳转
        self.driver.find_element(By.CSS_SELECTOR,"#artical-items-body > div:nth-child(1) > div > div.col > div.text-truncate > a > strong").click()
        self.driver.find_element(By.CSS_SELECTOR,"#details_article_title")
        BlogDriver.getScreeShot()
        self.driver.back()

        #搜索框是否可以输入跳转
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div.nav-item.d-none.d-md-flex.me-3 > div > form > div > input").send_keys("测试")
        BlogDriver.getScreeShot()
        self.driver.back()

        #夜间模式、日间模式是否可以点击切换
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > a.nav-link.px-0.hide-theme-dark > svg > path:nth-child(2)").click()
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > a.nav-link.px-0.hide-theme-light > svg > path:nth-child(2)").click()
        BlogDriver.getScreeShot()

        #用户个人详情是否可以点击出现弹窗
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_avatar").click()
        self.driver.find_element(By.CSS_SELECTOR,"#index_user_profile")
        BlogDriver.getScreeShot()

        #站内信息提醒是否可以点击出现弹窗
        self.driver.find_element(By.CSS_SELECTOR,"body > div.page > header.navbar.navbar-expand-md.navbar-light.d-print-none > div > div > div:nth-child(2) > div > a > svg").click()
        self.driver.find_element(By.CSS_SELECTOR,"#offcanvasEndLabel")
        BlogDriver.getScreeShot()
        self.driver.find_element(By.CSS_SELECTOR,"#index_message_offcanvasEnd > div.offcanvas-header > button").click()

    #站内信息提醒弹窗
    def ListInforRemPopupWindowTest(self):
        #对于收到信息点击是否出现回复弹窗
        self.driver.find_element(By.CSS_SELECTOR,"#index_div_message_list > div:nth-child(1) > div > div.col.text-truncate > a").click()
        self.driver.find_element(By.CSS_SELECTOR,"#index_message_detail_title")
        BlogDriver.getScreeShot()

        #点击弹窗回复按钮是否出现回复输入框
        self.driver.find_element(By.CSS_SELECTOR,"#btn_index_message_reply").click()
        self.driver.find_element(By.CSS_SELECTOR,"#index_message_reply_receive_user_name")

        #点击弹窗取消按钮是否可以关闭弹窗
        self.driver.find_element(By.CSS_SELECTOR, "#index_message_reply_cancel").click()
        self.driver.find_element(By.CSS_SELECTOR,"#offcanvasEndLabel")

        #不输入回复字段直接点击发送按钮
        self.driver.find_element(By.CSS_SELECTOR,"#index_div_message_list > div:nth-child(1) > div > div.col.text-truncate > a").click()
        self.driver.find_element(By.CSS_SELECTOR,"#btn_index_message_reply").click()
        self.driver.find_element(By.CSS_SELECTOR,"#btn_index_send_message_reply").click()
        BlogDriver.getScreeShot()

        #输入回复字段点击发送按钮
        self.driver.find_element(By.CSS_SELECTOR,"#index_div_message_list > div:nth-child(1) > div > div.col.text-truncate > a").click()
        self.driver.find_element(By.CSS_SELECTOR,"#btn_index_message_reply").click()
        self.driver.find_element(By.CSS_SELECTOR,"#index_message_reply_receive_content").send_keys("haha")
        self.driver.find_element(By.CSS_SELECTOR,"#btn_index_send_message_reply").click()
        BlogDriver.getScreeShot()
        self.driver.find_element(By.CSS_SELECTOR,"#index_message_offcanvasEnd > div.offcanvas-header > button").click()

    #用户个人详情弹窗
    def ListPersonalDetailsPopupWindowTest(self):
        #“我的帖子”是否可以点击跳转
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_avatar").click()
        self.driver.find_element(By.CSS_SELECTOR,"#index_user_profile").click()
        self.driver.find_element(By.CSS_SELECTOR,"#profile_nickname")
        BlogDriver.getScreeShot()
        self.driver.back()

        #“个人中心”是否可以点击跳转
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_avatar").click()
        self.driver.find_element(By.CSS_SELECTOR,"#index_user_settings").click()
        self.driver.find_element(By.CSS_SELECTOR,"#bit-forum-content > div.page-header.d-print-none > div > div > div > h2")
        BlogDriver.getScreeShot()
        self.driver.back()

        #“退出”是否可以点击退出网页
        self.driver.find_element(By.CSS_SELECTOR,"#index_nav_avatar").click()
        self.driver.find_element(By.CSS_SELECTOR,"#index_user_logout").click()
        self.driver.find_element(By.CSS_SELECTOR,"body > div > div > div > div:nth-child(1) > div > div.card.card-md > div > h2")
        BlogDriver.getScreeShot()
        #重新进入登录状态
        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("2890556976")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123321")
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()




